﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Diagnostics;

namespace System.Helper
{
    /// <summary>
    /// DLL文件编译模式判断
    /// </summary>
    public static class DebugMode
    {
        /// <summary>
        /// 判断DLL文件的编译模式(Debug,Release)
        /// </summary>
        /// <param name="assemblyFile">DLL文件的路径</param>
        /// <returns></returns>
        public static string GetDebugMode(string assemblyFile)
        {
            Assembly assembly = Assembly.LoadFrom(assemblyFile);
            DebuggableAttribute attr = assembly.GetCustomAttribute<DebuggableAttribute>();
            return attr.IsJITTrackingEnabled ? "Debug" : "Release";
        }

        public static T GetCustomAttribute<T>(this ICustomAttributeProvider provider) where T : Attribute
        {
            var attributes = provider.GetCustomAttributes(typeof(T), false);
            return attributes.Length > 0 ? attributes[0] as T : default(T);
        }
        
    }
    
}
